home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 242 / Issue 242 - April 2008 - DPCS0408DVD.ISO / Open Source / AutoHotKey / Source / AutoHotkey104705_source.exe / source / WinGroup.h < prev   
Encoding:
C/C++ Source or Header  |  2007-05-21  |  4.2 KB  |  110 lines

  1. /*
  2. AutoHotkey
  3.  
  4. Copyright 2003-2007 Chris Mallett (support@autohotkey.com)
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15. */
  16.  
  17. #ifndef wingroup_h
  18. #define wingroup_h
  19.  
  20. #include "defines.h"
  21. #include "SimpleHeap.h" // for WinGroup's overloaded new/delete operators.
  22.  
  23.  
  24. // NOTE: This module is separate from the others because:
  25. // 1) If it were in script.h/cpp it would add clutter to that already large file.
  26. // 2) If it were in window.h/cpp it causes mutual-dependency problems between header
  27. //    (probably correctible, but it's fine this way).
  28.  
  29.  
  30. class Label;
  31. class WindowSpec
  32. {
  33. public:
  34.     char *mTitle, *mText, *mExcludeTitle, *mExcludeText;
  35.     Label *mJumpToLabel;
  36.     WindowSpec *mNextWindow;  // Next item in linked list.
  37.     WindowSpec(char *aTitle = "", char *aText = "", Label *aJumpToLabel = NULL
  38.         , char *aExcludeTitle = "", char *aExcludeText = "")
  39.         // Caller should have allocated some dynamic memory for the given args if they're not
  40.         // the empty string.  We just set our member variables to be equal to the given pointers.
  41.         : mTitle(aTitle), mText(aText), mExcludeTitle(aExcludeTitle), mExcludeText(aExcludeText)
  42.         , mJumpToLabel(aJumpToLabel), mNextWindow(NULL) // mNextWindow(NULL) is also required for thread-safety.
  43.     {}
  44.     void *operator new(size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
  45.     void *operator new[](size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
  46.     void operator delete(void *aPtr) {}
  47.     void operator delete[](void *aPtr) {}
  48. };
  49.  
  50.  
  51.  
  52. class WinGroup
  53. {
  54. private:
  55.     // The maximum number of windows to keep track of:
  56.     #define MAX_ALREADY_VISITED 500
  57.     static WinGroup *sGroupLastUsed;
  58.     static HWND *sAlreadyVisited;  // Array.  It will be dynamically allocated on first use.
  59.     static int sAlreadyVisitedCount;
  60.     bool mIsModeActivate;
  61.  
  62.     static void MarkAsVisited(HWND aWnd)
  63.     {
  64.         // For peace of mind, do dupe-check to rule out, once and for all,
  65.         // the possibility of any unusual conditions where the list might get
  66.         // quickly filled up with dupes:
  67.         for (int i = 0; i < sAlreadyVisitedCount; ++i)
  68.             if (sAlreadyVisited[i] == aWnd) // It's already in the list.
  69.                 return;
  70.         if (sAlreadyVisitedCount >= MAX_ALREADY_VISITED)
  71.             // Can't store any more. Don't bother displaying an error (too unlikely).
  72.             return;
  73.         sAlreadyVisited[sAlreadyVisitedCount++] = aWnd;
  74.     }
  75.  
  76.     ResultType Update(bool aIsModeActivate);
  77.  
  78. public:
  79.     char *mName;    // The name of the group.
  80.     WindowSpec *mFirstWindow, *mLastWindow;
  81.     WinGroup *mNextGroup;  // Next item in linked list.
  82.     UINT mWindowCount;
  83.  
  84.     ResultType AddWindow(char *aTitle, char *aText, Label *aJumpToLabel, char *aExcludeTitle, char *aExcludeText);
  85.     ResultType ActUponAll(ActionTypeType aActionType, int aTimeToWaitForClose);
  86.     ResultType CloseAndGoToNext(bool aStartWithMostRecent);
  87.     ResultType Activate(bool aStartWithMostRecent, WindowSpec *aWinSpec = NULL, Label **aJumpToLabel = NULL);
  88.     ResultType Deactivate(bool aStartWithMostRecent);
  89.     bool IsEmpty() {return mFirstWindow == NULL;}
  90.     WindowSpec *IsMember(HWND aWnd, global_struct &aSettings);
  91.     WinGroup(char *aGroupName)
  92.         // The caller must ensure that aGroupName is non-null and non-empty-string.
  93.         : mName(aGroupName) // Caller gave us a pointer to dynamic memory for this.
  94.         , mFirstWindow(NULL), mLastWindow(NULL)
  95.         , mWindowCount(0)
  96.         , mNextGroup(NULL) // v1.0.41: Required for thread-safety, but also for maintainability.
  97.         , mIsModeActivate(true) // arbitrary default.
  98.     {}
  99.     void *operator new(size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
  100.     void *operator new[](size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
  101.     void operator delete(void *aPtr) {}
  102.     void operator delete[](void *aPtr) {}
  103. };
  104.  
  105.  
  106. BOOL CALLBACK EnumParentFindAnyExcept(HWND aWnd, LPARAM lParam);
  107. BOOL CALLBACK EnumParentActUponAll(HWND aWnd, LPARAM lParam);
  108.  
  109. #endif
  110.